/**
 * Created by cxj on 2016/2/22.
 */
var grid;
var bootbox_global;

var grid_show;

//显示签到信息
function showcheckin(objid,datarow) {

    bootbox = bootbox_global;

    var obj = grid.date_list[datarow];


    //alert(objid);


   // intervalid = setInterval(setTimeOutController,0.5);

   // grid_show = new Grid("/workerCheckin/getListPaging", $("#table_my_toast1"), $("#paging_my_toast1"), 1, 10, columns, "worker_id="+objid, 20);

    //初始化
    //grid_show.Init();

   // bootbox_global.dialog({
    //    message: "<table class=\"table_list\" id=\"table_my_toast1\"></table> <div class=\"page_control\" id=\"paging_my_toast1\"><ul></ul>",
   // });

    //bootbox_global.dialog({
    //    message: "<iframe src='/worker/workerlist' style='width: 100%;min-height: 400px;'></iframe>",
    //});
    //return;


    //发送请求
    send_request_direct("/workerCheckin/getListPaging", "worker_id="+objid, function process_data(data) {


      //  alert(data.data.data.length);

        var columns = [
            {title : '编号',dataIndex :'User_ID',dataSource:function(data,datarow,gridobj,current_column) {

                return "<span>"+(parseInt(datarow)+1)+"</span>";
            }},
            { title: '签到时间', dataIndex: 'create_time',},
            { title: '操作人', dataIndex: 'created_by',},


        ];

        var message = getGridInfo(data.data.data,columns);

        bootbox_content_alert(message);


    }, function process_fail(data) {

        //操作失败
        AlertError(bootbox, data.msg);


    });

}


define([
    "jquery",
    "IO",
    "bootbox"
], function($,IO,bootbox) {

    bootbox_global = bootbox;
    $(function () {

        //每列数据列性
        var columns = [
            {title : '编号',dataIndex :'User_ID',dataSource:function(data,datarow,gridobj,current_column) {

                return "<span>"+parseInt( (gridobj.current_page-1)*gridobj.page_rows+parseInt(datarow)+1)+"</span>";
            }},
            { title: '用户id', dataIndex: 'worker_id',},
            { title: '手机号', dataIndex: 'mobile',},
            {title : '认证状态',dataIndex :'User_ID',dataSource:function(data,datarow,gridobj,current_column) {

                var is_verify = data[datarow].is_verify;

                if(is_verify == 0)
                    return "<span class='label-default'>未提交</span>";
                if(is_verify == 1)
                    return "<span onclick=\"bootbox_content_alert('"+data[datarow].reason+"')\" class='label-success'>认证成功<span class='glyphicon glyphicon-info-sign' aria-hidden='true'></span></span>";
                if(is_verify == 2)
                    return "<span class='label-info'>认证中</span>";
                if(is_verify == 3)
                    return "<span  onclick=\"bootbox_content_alert('"+data[datarow].reason+"')\" class='label-danger'>认证失败<span class='glyphicon glyphicon-info-sign' aria-hidden='true'></span></span>";


            }},
            { title: '姓名', dataIndex: 'real_name',},
            { title: '头像', dataIndex: 'avatar',dataSource:function(data,datarow,gridobj,current_column) {

                var avatar = data[datarow].avatar;

                if(avatar.length == 0)
                    return "";
                else
                    return "<img class='girdimg img-thumbnail' onclick=\"viewUrl('"+avatar+"')\" src='"+avatar+"'/>"


            }},
            { title: '手持照', dataIndex: 'avatar',dataSource:function(data,datarow,gridobj,current_column) {

                var avatar = data[datarow].pic_idcard;

                if(avatar == undefined)
                    return "";
                if(avatar.length == 0)
                    return "";
                else
                // return "<img width='60px' src='"+avatar+"'/>"
                    return "<img class='girdimg img-thumbnail' onclick=\"viewUrl('"+avatar+"')\" src='"+avatar+"'/>"


            }},

            { title: '工种', dataIndex: 'type_name',},
            //{ title: '工号', dataIndex: 'worker_num',},
            { title: '单价', dataIndex: 'avatar',dataSource:function(data,datarow,gridobj,current_column) {

                var price = data[datarow].price;

                return price+"元/m<sup>2</sup>"



            }},
            { title: '工龄', dataIndex: 'work_year',},
            { title: '性别', dataIndex: 'gender',dataSource:function(data,datarow,gridobj,current_column) {

            var gender = data[datarow].gender;

            if(gender == 0)
                return "女";
            if(gender == 1)
                return "男";

                return "";



        }},
            {
                title: '签到天数', dataIndex: 'gender', dataSource: function (data, datarow, gridobj, current_column) {

                var obj = data[datarow];

               // return obj.check_in_count+"<span class='glyphicon glyphicon-info-sign' aria-hidden='true'></span>";

                return "<span onclick=\"showcheckin('"+obj.worker_id+"')\" >"+obj.check_in_count+"<span class='glyphicon glyphicon-info-sign' aria-hidden='true'></span></span>";





            }
            },
            { title: '身份证', dataIndex: 'idcard',},
            { title: '评分', dataIndex: 'starnum'},
            { title: '施工图图列表', dataIndex: 'avatar',dataSource:function(data,datarow,gridobj,current_column) {

                if(isNull( data[datarow].construct_pic_list))
                    return "";
                var designpicarray = data[datarow].construct_pic_list.split(",");

                var html ="";

                for(var i=0;i<designpicarray.length;i++)
                {

                    html +="<img class='girdimgthunb' onclick=\"viewUrl('"+designpicarray[i]+"')\" src='"+designpicarray[i]+"'/>&nbsp;";

                }

                return html;

            }},
            { title: '注册时间', dataIndex: 'create_time',},


        ];


        //数组初始化

        function dataInit() {
            grid = new Grid("/worker/getworkerlist", $("#table_my_toast"), $("#paging_my_toast"), 1, 10, columns, get_input_param(), 20);

            //初始化
            grid.Init();
        }

        //获取输入框内容
        function get_input_param() {

            var param="mobile="+$("#mobile").val()+"&real_name="+$("#real_name").val()+"&idcard="+$("#idcard").val()+"&worker_num="+$("#worker_num").val();

            return param;

        }
        dataInit();
        //查询
        $("#query").bind("click", function () {
            dataInit();
        });
    });


});